<?php

namespace App\Model;

use EasySwoole\ORM\AbstractModel;
use EasySwoole\ORM\Db\Cursor;
use EasySwoole\ORM\Db\CursorInterface;
use EasySwoole\ORM\Exception\Exception;
use Throwable;

/**
 * Class WithdrawOrderModel
 * Create With Automatic Generator
 * @property $id
 * @property $user_id
 * @property $withdraw_amount
 * @property $create_time
 * @property $update_time
 * @property $status
 * @property $payorderid
 * @property $handle_type
 * @property $commission
 * @property $true_money
 */
class WithdrawOrderModel extends AbstractModel
{
    protected $tableName = 'bee_withdraw_order';

    protected $primaryKey = 'id';

    protected $autoTimeStamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

    /**
     * 添加体现订单
     * @param int $userId
     * @param float $money
     * @param int $handleType
     * @param float $commission
     * @param float $trueMoney
     * @return WithdrawOrderModel|array|bool|AbstractModel|Cursor|CursorInterface|null
     * @throws \EasySwoole\Mysqli\Exception\Exception
     * @throws Exception
     * @throws Throwable
     */
    public function addWithdrawOrder(int $userId, float $money, int $handleType, float $commission, float $trueMoney)
    {
        $res = $this->data([
            'user_id' => $userId,
            'withdraw_amount' => $money,
            'create_time' => time(),
            'update_time' => time(),
            'status' => 2,
            'payorderid' => '',
            'handle_type' => $handleType,
            'commission' => $commission,
            'true_money' => $trueMoney,
        ], false)->save();

        return $this->get($res);
    }
}